package com.bestsonic.crawler.utils;

import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SqlSessionFactoryUtils {
	
	private static SqlSessionFactory sqlSessionFactory;
	
	public static SqlSessionFactory getSqlSesisonFactory(){
		
		if(sqlSessionFactory == null){
			InputStream in = null;
			try{
				in = Resources.getResourceAsStream("mybatis/SqlMapConfig.xml");
				sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		return sqlSessionFactory;
	}
	public static SqlSession openSession(){
		return sqlSessionFactory.openSession();
	}
	
}
